﻿using System;
using System.Collections;
using System.Web.Caching;
using System.Web.Hosting;

namespace LogikBug.ModularMvc.Hosting
{
	public class AssemblyResourceProvider : VirtualPathProvider
	{
		#region Fields



		#endregion

		#region Properties

		public IModuleProvider Provider
		{
			get
			{
				return ModuleProvider.Current;
			}
		}

		#endregion

		#region Methods

		public override bool FileExists(string virtualPath)
		{
			return (AssemblyResourceUtility.IsAppResourcePath(virtualPath) || base.FileExists(virtualPath));
		}

		public override VirtualFile GetFile(string virtualPath)
		{
			if (AssemblyResourceUtility.IsAppResourcePath(virtualPath))
			{
				return new AssemblyResourceVirtualFile(virtualPath);
			}

			return base.GetFile(virtualPath);
		}

		public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
		{
			if (!AssemblyResourceUtility.IsAppResourcePath(virtualPath))
			{
				return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
			}

			return null;
		}

		#endregion
	}
}
